using System.Xml.Linq;
using Engine;
using Game;

namespace SCIENEW {
    public class FluidTankWidget : CanvasWidget {

        public ComponentFluidTank m_componentTank;

        public GridPanelWidget m_inventoryGrid;

        public TankWidget m_tankWidget;

        public FluidTankWidget(IInventory inventory, ComponentFluidTank componentTank) {
            m_componentTank = componentTank;
            XElement node = ContentManager.Get<XElement>("Widgets/FluidTankWidget");
            LoadContents(this, node);
            m_inventoryGrid = Children.Find<GridPanelWidget>("InventoryGrid");
            m_tankWidget = Children.Find<TankWidget>("Tank");
            m_tankWidget.AssignTank(componentTank, 0);
            int num = 10;
            for (int k = 0; k < m_inventoryGrid.RowsCount; k++) {
                for (int l = 0; l < m_inventoryGrid.ColumnsCount; l++) {
                    var inventorySlotWidget2 = new InventorySlotWidget();
                    inventorySlotWidget2.AssignInventorySlot(inventory, num++);
                    m_inventoryGrid.Children.Add(inventorySlotWidget2);
                    m_inventoryGrid.SetWidgetCell(inventorySlotWidget2, new Point2(l, k));
                }
            }
        }

        public override void Update() {
            if (!m_componentTank.IsAddedToProject) {
                ParentWidget.Children.Remove(this);
            }
        }
    }
}